var GenTransSerialUtils = {
	genTransSerialNo : function(systemId) {
		checkRequestId(systemId, 4);
		var transSerial = "";
		var f_1 = "1";
		var f_2_5 = systemId;
		var f_6_7 = get6_7();
		var f_8 = "7";
		var f_9 = "0";
		var dt = new Date();
		var f_10_26 = formatDate(dt, "yyyyMMddhhmmssS");
		var f_27_32 = get27_32();
		transSerial = f_1 + f_2_5 + f_6_7 + f_8 + f_9 + f_10_26 + f_27_32;
		return transSerial;
	}
};

/**
 * 对Date的扩展，将 Date 转化为指定格式的String * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q)
 * 可以用 1-2 个占位符 * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
 * eg: 
 *  (newDate()).pattern("yyyy-MM-dd hh:mm:ss.S")==> 2006-07-02 08:09:04.423      
 *  (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04      
 *  (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04      
 *  (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04      
 *  (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18      
 */  
function formatDate(dateObj, formatStr) {
	var o = {         
	    "M+" : dateObj.getMonth()+1, //月份         
	    "d+" : dateObj.getDate(), //日         
	    "h+" : dateObj.getHours()%12 == 0 ? 12 : dateObj.getHours()%12, //小时         
	    "H+" : dateObj.getHours(), //小时         
	    "m+" : dateObj.getMinutes(), //分         
	    "s+" : dateObj.getSeconds(), //秒         
	    "q+" : Math.floor((dateObj.getMonth()+3)/3), //季度         
	    "S" : dateObj.getMilliseconds() //毫秒         
	    }; 
	
    var week = {         
	    "0" : "/u65e5",         
	    "1" : "/u4e00",         
	    "2" : "/u4e8c",         
	    "3" : "/u4e09",         
	    "4" : "/u56db",         
	    "5" : "/u4e94",         
	    "6" : "/u516d"        
	    };  
    
    if(/(y+)/.test(formatStr)){         
        formatStr = formatStr.replace(RegExp.$1, (dateObj.getFullYear()+"").substr(4 - RegExp.$1.length));         
    }         
    if(/(E+)/.test(formatStr)){         
        formatStr = formatStr.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[dateObj.getDay()+""]);         
    }         
    for(var k in o){         
        if(new RegExp("("+ k +")").test(formatStr)){         
            formatStr = formatStr.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));         
        }         
    }
    return formatStr;      
};

function get6_7() {
	var a = randomNum(0, 10);
	var b = randomNum(0, 10);
	return a + "" + b;
}

function get27_32() {
	var a = randomNum(0, 10);
	var b = randomNum(0, 10);
	var c = randomNum(0, 10);
	var d = randomNum(0, 10);
	var e = randomNum(0, 10);
	var f = randomNum(0, 10);
	return a + "" + b + c + "" + d + e + "" + f;
}

function randomNum(min, max) {
	var range = max - min;
	var rand = Math.random();
	return (min + Math.round(rand * range));
}

function checkRequestId(param, length) {
	var flag = true;
	if (param == null || param == undefined || param == ""
			|| param.length != length) {
		flag = false;
	} else {
		var arrays = param.toCharArray();
		for (var i = 0; i < arrays.length; i++) {
			var c = arrays[i];
			if (c < '0' || c > '9') {
				flag = false;
				break;
			}
		}
	}
	if (!flag) {
		throw "参数格式异常，必须为指定长度的数字组成。";
	}
}